package com.ninthgroup.controller;

import com.ninthgroup.entity.Dept;
import com.ninthgroup.service.DeptService;
import com.ninthgroup.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：Student A Wei
 * @date ：Created in 2022/10/14 19:18
 * @description: 部门管理的控制层
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    // 查询部门
    @RequestMapping("/select")
    public Result select(@RequestBody Dept dept) {
        return deptService.selectAll(dept.getDeptName(), dept.getDeptStatus());
    }

    // 添加部门
    @RequestMapping("/add")
    @ResponseBody
    public Result add(@RequestBody Dept dept) {
        return deptService.insertAdd(dept);
    }

    //删除部门
    @RequestMapping("/delete")
    public Result delete(Integer deptId) {
        return deptService.deleteBydeptId(deptId);
    }

    //修改部门表
    @RequestMapping("/update")
    @ResponseBody
    public Result update(@RequestBody Dept dept) {
        return deptService.update(dept);
    }


    @GetMapping("/updateStatus")
    public Result updateStatus(Integer deptId, Integer deptStatus){
        return deptService.updateStatus(deptId,deptStatus);
    }

    @GetMapping("/getNames")
    public Result getNames(Integer deptId){
        return deptService.getOfficeName(deptId);
    }
}